<template>
    <div class="opt-select-sti">
        <div class="menu">
            <a 
            class="menu-btn"
            v-for="(item, index) in listOptionArr"
            :key="index"
            :class="activeListOpt === item ? 'active' : ''"
            @click="clickOpt(item)"
            >{{listOption[item].name}}</a>
            <div class="line"></div>
        </div>
        <div class="statistics">
            <div 
            v-for="(item, index) in listOptStiArr" 
            class="opt-statistics"
            :key="index"
            v-show="activeListOpt === item"
            >
                {{listOptSti[item]}}
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'OptSelectSti',
    props: {
        listOption: { // 所有选项
            type: Object,
            default: {}
        },
        activeListOpt: { // 默认选项
            type: String,
            default: ''
        },
        listOptSti: { // 选项统计
            type: Object,
            default: {}
        },
    },
    methods: {
        clickOpt(option) {
            if (option) {
                this.$emit('chooseOpt', option)
            }
        }
    },
    computed: {
        listOptionArr() {
            return Object.keys(this.listOption)
        },
        listOptStiArr() {
            return Object.keys(this.listOptSti)
        },
    }
}
</script>

<style lang="scss" scoped>
.opt-select-sti {
    .menu {
        height: 40px; 
        width: 100%;
        display: flex;
        text-align: center;
        position: relative;
        border-bottom: 1px solid #eeeeee;
        background: white;

        .menu-btn {
            height: 100%;
            width: 50%;
            color: #333333;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .active {
            background: #0077bf;
            color: white;
            font-weight: bold;
        }

        .line {
            position: absolute;
            width: 100%;
            height: 2px;
            background: #0077bf;
            left: 0px;
            bottom: -1px;
        }
    }

    .statistics {
        height: 30px;
        line-height: 30px;
        text-align: center;
        background: #f6f6f6;
        font-size: 12px;
        color: #999999;

        .opt-statistics {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            width: 100%;
        }
    }
}
</style>